package com.adun.springsecurityoauth2demo.service;


import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;


/**
 * @author Zhu Dunfeng
 * @date 2024/11/24 14:53
 */
@Component
public class ClientDetailServiceImpl implements ClientDetailsService {
    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        // TODO 根据clientId查询数据库

        // 查询除对应信息
        BaseClientDetails baseClientDetails = new BaseClientDetails();
        baseClientDetails.setClientId("111");
        baseClientDetails.setClientSecret("secret");
        baseClientDetails.setScope(Arrays.asList("all"));
        baseClientDetails.setRegisteredRedirectUri(new HashSet<>(Arrays.asList("")));
        baseClientDetails.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("admin,normal,ROLE_abc,/main.html,/main1.html,/insert,/delete"));
        baseClientDetails.setAccessTokenValiditySeconds(60);
        baseClientDetails.setRefreshTokenValiditySeconds(60 * 5);
        return baseClientDetails;
    }
}
